package com.scrawler.util;


/**
*   类说明
*  
*   @Description     把String类型的时间转换成long类型的时间返回
*   @creator         tangkun
*   @create-time     2011-7-21
*   @revision        $Id
*/


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public abstract class DateUtils {
	
	public static long string2Long(String time)
	{
		if(time == null)
			return -1;
		SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			// 对字符串进行转换
			return format.parse(time).getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}				
		return -1;
	}
	
	public static String long2String(long time){
		SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date(time);  
		return format.format(date);
	}
	
	
	public static String getCurrentStringTime()
	{
		Date date = new Date();
		SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = format.format(date);
		return time;
	}
	
	
	public static void main(String args[])
	{
		long time = DateUtils.string2Long("2011-10-14 23:36:26");
		System.out.println(time);
	}
		
}
